﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ATEDiagnoser
{
    public class Setting
    {
        public Dictionary<string, string> UserOper { get; set; }

        public Dictionary<string, CATE> ATE { get; set; }

        public Dictionary<string,Dictionary<string,string>> Common { get; set; }


        [JsonIgnore]
        public string this[string key]
        {
            get
            {
                foreach (var item in Common) 
                {
                    if (key.StartsWith(item.Key))
                    {
                        return Common[item.Key][key];
                    }
                }
                return null;
            }
            set
            {
                foreach (var item in Common)
                {
                    if (key.StartsWith(item.Key))
                    {
                        Common[item.Key][key] = value;
                    }
                }
            }
        }


        /// <summary>
        /// 判断ATE安装在哪个盘
        /// </summary>
        /// <returns></returns>
        public void JudgeATEDevice(string ateName, CATE ate) 
        {
            var temp = ATE["Common"]["judge_path"].Trim().Split(';');
            foreach (var item in temp)
            {
                var t = item.Trim();
                var t2 = t + ate["dir"] + ate["shortcut"];
                if (File.Exists(t + ate["dir"] + ate["shortcut"]))
                {
                    ate["device"] = t;
                    return;
                }
            }
            MsgShow.Hint($"未找到{ateName}的主文件夹！");
        }
        /// <summary>
        /// 自动判断Hangs在哪个盘
        /// </summary>
        public void JudgeHangsDevice()
        {
            var temp = this["hangs_judge"].Trim().Split(';');
            foreach (var item in temp)
            {
                var t = item.Trim();
                if (Directory.Exists(t + this["hangs_dir"]))
                {
                    this["hangs_device"] = t;
                    return;
                }
            }
        }

        
    }

    
    public class CATE :Dictionary<string, string>
    {
        
    }

      
}
